/**
 * Created by Mark_ren on 2016/11/28.
 * 苟富贵,無相忘
 */
var co = require('co');
var seqModule = require('../../../routes/createModules');
var seq = new seqModule();
var util = require('../../../common/util');

var commentController = {
    /**
     *  *  脑血管时间 病例讨论 评论接口 根据ID查询
     * @param req
     * @param res
     */
    getCommentListByID: function (req, res) {
        co(function () {
            var params = {};
            var paramT = {};
            params["titleId"] = req.params.ID;
            var include = [{ model: seq.memberModule, attributes: ['name', 'hospitalName', 'hospitalOffices'] }];
            paramT.include = include;
            params["state"] = 1;
            paramT["where"] = params;
            paramT["order"] = [['createTime', 'desc']];
            seq.commentLogModule.findAll(paramT).then(function (result) {
                res.json({ "success": true, "msg": "查询成功", "result": result });
            });
        }).catch(function (e) {
            res.json({ 'success': false, 'msg': '查询失败' });
            console.log(e);
        })

    },

    /**
     *  增加评论
     * @param req
     * @param res
     */
    addComment: function (req, res) {
        co(function () {
            var uuid = util.getUUID();
            req.query.id = uuid;
            req.query.createTime = util.getNowTime();
            req.query.content = decodeURI(req.query.content);
            seq.commentLogModule.create(req.query).then(function (result) {
                res.status(200).json({
                    success: true,
                    message: "添加成功",
                    result: result
                });
            })
        }).catch(function (e) {
            res.json({ 'success': false, 'msg': '新增失败' });
            console.log(e);
        })

    }
}
module.exports = commentController;